<template>
  <view>
    <view class="address-window" :class="value === true ? 'on' : ''">
      <view class="title">
        选择发票
        <text class="iconfont icon-guanbi" @click="closeAddress"></text>
      </view>
      <view class="list" v-if="invoiceList.length">
        <view
          class="item acea-row row-between-wrapper"
          :class="item.invoiceId === checked ? 'font-color-red' : ''"
          v-for="(item, index) in invoiceList"
          @click="tapAddress(index)"
          :key="index"
        >
          <!-- <text class="iconfont icon-ditu" :class="item.invoiceId === checked ? 'font-color-red' : ''"></text> -->
          <view class="addressTxt">
            <view class="name" :class="item.invoiceId === checked ? 'font-color-red' : ''">
              {{ item.invoiceName }}
              <text class="phone">{{ item.phone }}</text>
            </view>
            <view class="line1">
              {{ item.licenseNumber }}
            </view>
          </view>
          <text class="iconfont icon-complete" :class="item.invoiceId === checked ? 'font-color-red' : ''"></text>
        </view>
      </view>
      <view class="pictrue" v-if="invoiceList.length < 1">
        暂无添加发票地址
      </view>
      <view class="addressBnt bg-color-red" @click="goAddressPages">新加发票</view>
    </view>
    <view class="mask" @touchmove.prevent :hidden="value === false" @click="closeAddress"></view>
  </view>
</template>
<script>
import { getInvoice } from "@/api/user";

export default {
  name: "InvoiceIdWindow",
  props: {
    value: Boolean,
    checked: String
  },
  data: function() {
    return {
      invoiceList: [],
      current: 0,
      cartId: 0,
      pinkId: 0,
      couponId: 0
    };
  },
  mounted: function() {},
  methods: {
    getInvoice: function() {
      let that = this;
      getInvoice({
		  page: 1,
		  limit: 999
	  }).then(res => {
		  console.log(res.data)
        that.invoiceList = res.data;
      });
    },
    closeAddress() {
      this.$emit("input", false);
    },
    goAddressPages: function() {
      this.$yrouter.push({ path: "/userPack/pages/user/invoice/AddInvoice/index" });
      this.$emit("redirect");
    },
    tapAddress: function(index) {
      this.$emit("checked", this.invoiceList[index]);
      this.$emit("input", false);
    }
  }
};
</script>
